import * as React from 'react';
import {Button, View, Text} from 'react-native';

import {TouchableWithoutFeedback} from 'react-native-gesture-handler';
var PushNotification = require('react-native-push-notification');

// var Sound = require('react-native-sound');

PushNotification.configure({
  onNotification(notification) {
    console.log('onNotification')
    console.log( notification );
    // that.handleNotification(notification);
  },
});

const sound = 'https://tsn.baidu.com/text2audio?tex=%E6%82%A8%E6%9C%89%E8%AE%A2%E5%8D%95%E4%BA%86%EF%BC%8C%E8%AF%B7%E5%8F%8A%E6%97%B6%E6%9F%A5%E6%94%B6&lan=zh&cuid=***&ctp=1&tok=24.f9bf1276e6eca655cf2df4814343e32b.2592000.1605665146.282335-22840569'

export default class App extends React.Component {
  push = () => {
    // alert(1)
    console.log(1111)

    PushNotification.localNotification({
      title: '新订单',
      message: '您有新订单了',
      playSound: true,
      vibrate: true,
      vibration: 300,
      badge: 100
    });

    return;

    // Load the sound file 'whoosh.mp3' from the app bundle
    // See notes below about preloading sounds within initialization code below.
    var whoosh = new Sound(sound, null, (error) => {
      if (error) {
        console.log('failed to load the sound', error);
        return;
      }

      // loaded successfully
      console.log(
        'duration in seconds: ' +
          whoosh.getDuration() +
          'number of channels: ' +
          whoosh.getNumberOfChannels(),
      );

      // Play the sound with an onEnd callback
      whoosh.play((success) => {
        if (success) {
          console.log('successfully finished playing');
        } else {
          console.log('playback failed due to audio decoding errors');
        }
      });
    });

    // Release the audio player resource
    whoosh.release();
  };

  render() {
    return (
      <View style={{flex: 1, backgroundColor: 'red'}}>
        <Text>hello world</Text>
        <Text>hello world</Text>
        <Text>hello world</Text>
        <Text>hello world</Text>
        <TouchableWithoutFeedback onPress={this.push}>
          <Text>push</Text>
        </TouchableWithoutFeedback>
      </View>
    );
  }
}
